<?php

/**
 * Restore MySQL test Upload
 *
 * PHP version 5
 *
 * Copyright @ 2013 François Cero
 *
 * This file is part of Galette (http://galette.tuxfamily.org).
 *
 * Plugin MySqlsave is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Plugins
 * @package   MySqlsave
 *
 * @author    François Cero <cerol@laposte point net>
 * @copyright 2013 François Cero
 * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
 * @version   0.1
 * @link      http://galette.tuxfamily.org
 * @since     Available since 0.7
 */


define('GALETTE_BASE_PATH', '../../');
require_once GALETTE_BASE_PATH . 'includes/galette.inc.php';
if ( !$login->isLogged() ) {
    header('location: ' . GALETTE_BASE_PATH . 'index.php');
    die();
}
if (!$login->isSuperAdmin()) {
    header('location: ' . GALETTE_BASE_PATH . 'index.php');
    die();
}
require_once '_config.inc.php';

$upload_dir = dirname(__FILE__).'/restores/';



// $taille_maxiRESTORE = 400000;  this parameter is now defined in _config.inc.php
$taille = filesize($_FILES['restorefile']['tmp_name']);
$extensions = array('.sql', '.SQL', '.gz', '.GZ');
$extension = strrchr($_FILES['restorefile']['name'], '.'); 
//Début des vérifications de sécurité...
if(!in_array($extension, $extensions)) //Si l'extension n'est pas dans le tableau
{
     $erreur = _T("RESTORE.EXT");
}
if($taille>$taille_maxiRESTORE)
{
     $erreur = _T("RESTORE.SIZE");
}

if(!isset($erreur)) //S'il n'y a pas d'erreur, on continu
{
$filen= $_FILES['restorefile']['name'];
$uploadd= $_FILES['restorefile']['tmp_name'];
move_uploaded_file($_FILES['restorefile']['tmp_name'],$upload_dir.$filen); 

 header('Location: bigdump.php'); 
}
else {

/**
 * Le traitement est terminé, on affiche le template
 */
$tpl->assign('page_title', _T("RESTORE.ERTITLE"));
//Set the path to the current plugin's templates,
//but backup main Galette's template path before
$orig_template_path = $tpl->template_dir;
$tpl->template_dir = 'templates/' . $preferences->pref_theme;
$tpl->assign('error', $erreur);

$content = $tpl->fetch('restoreupl.tpl', SAVE_SMARTY_PREFIX);
$tpl->assign('content', $content);
//Set path to main Galette's template
$tpl->template_dir = $orig_template_path;
$tpl->display('page.tpl', SAVE_SMARTY_PREFIX);


}
